//
//  OAConfigVC.m
//  OAMobile
//
//  Created by wangweichao on 2018/11/13.
//  Copyright © 2018年 李天露. All rights reserved.
//

#import "OAConfigVC.h"

@interface OAConfigVC ()
@property (nonatomic, strong) UILabel *environmentLabel;
@property (nonatomic, strong) UISwitch* environmentSW;
@property (nonatomic, strong) UITextField *inputUrl;
@property (nonatomic, strong) UIButton *save;

@property (nonatomic, strong) UIButton *cancel;
@end

@implementation OAConfigVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.cancel = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-70, 50, 50, 31)];
    self.cancel.backgroundColor = [UIColor grayColor];
    [self.cancel setTitle:@"取消" forState:UIControlStateNormal];
    [self.cancel addTarget:self action:@selector(cancelView) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:self.cancel];
    
    
    self.inputUrl = [[UITextField alloc] initWithFrame:CGRectMake(12, 50, 200, 31)];
    self.inputUrl.textAlignment = NSTextAlignmentLeft;
    self.inputUrl.backgroundColor = [UIColor lightGrayColor];
    self.inputUrl.placeholder = @"自定义测试地址";
    self.inputUrl.font = [UIFont systemFontOfSize:16];
    [self.view addSubview: self.inputUrl];
    
    self.save = [[UIButton alloc] initWithFrame:CGRectMake(230, 50, 50, 31)];
    self.save.backgroundColor = [UIColor orangeColor];
    [self.save setTitle:@"保存" forState:UIControlStateNormal];
    [self.save addTarget:self action:@selector(saveEvent) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:self.save];
    [self.view bringSubviewToFront:self.inputUrl];
    [self.view bringSubviewToFront:self.save];
    
    
}

-(void)cancelView{
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(void)saveEvent{
    UIAlertView *alert;
    if (self.inputUrl.text.length==0) {
        alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"输入不能为空" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
    NSUserDefaults *uf = [NSUserDefaults standardUserDefaults];
    [uf setValue:self.inputUrl.text forKey:@"url"];
    [uf synchronize];
    alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"保存成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
